package 二叉搜索数;

/**
 * https://leetcode.cn/problems/insert-into-a-binary-search-tree/
 *
 ** 题解：https://mp.weixin.qq.com/s?__biz=MzAxODQxMDM0Mw==&mid=2247493456&idx=1&sn=ad7dbf1422bdfd755e0cef046cb71e88&chksm=9bd41958aca3904ec5ae7891f8d275d597a1626ebd525aaa068e2e78a075a92d5ebac786dc8a&scene=178&cur_album_id=2165105273311494144#rd
 */
public class _701_二叉搜索树中的插入操作 {

    public TreeNode insertIntoBST(TreeNode root, int val) {
        // 找到位置，插入
        if (root == null) return new TreeNode(val);

        if (root.val < val) {
            root.right = insertIntoBST(root.right, val);
        } else {
            root.left = insertIntoBST(root.left, val);
        }

        return root;
    }
}
